package org.dce.screencapturer.actions.objects;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.Arrays;
import java.util.List;

import org.dce.screencapturer.Drawing;
import org.dce.screencapturer.objects.DrawingObject;
import org.dce.screencapturer.util.IconFactory;

@SuppressWarnings("serial")
public class MoveUpAction extends ObjectAction {

	public MoveUpAction() {
		super("categories.object", "actions.moveUp", IconFactory.getIcon("/images/move-up.png"));
	}

	@Override
	protected boolean acceptObject(DrawingObject anObject) {
		return true;
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		
		DrawingObject object = getObject();
		
		Drawing drawing = getDrawing();
		
		List<Component> components = Arrays.asList(drawing.getComponents());
		
		int index = components.indexOf(object);
		
		if (index > 0){
			drawing.remove(object);
			drawing.add(object, index-1);
			drawing.repaint();
		}

	}

}
